<template>
  <view class="system-button">
    <button @click="bindWechatPhone">绑定手机/微信</button>
    <button @click="$goUrl(`/pages/login/userTready`)">隐私政策</button>
    <button @click="exitLogin">退出登录</button>
    <!-- <button @click="toOpen">测试</button>
    <button @click="pay">支付</button> -->
  </view>
</template>
<script setup>
import { onLoad } from "@dcloudio/uni-app";

const bindWechatPhone = () => {
  if (uni.getStorageSync("token")) {
    uni.navigateTo({
      url: "/pages/mine/wechat",
    });
    // window.location.href = '/pages/mine/wechat'
  } else {
    uni.navigateTo({
      url: "/pages/login/login",
    });
  }
};

const exitLogin = () => {
  uni.showModal({
    title: "提示",
    content: "退出登录",
    success: function (res) {
      if (res.confirm) {
        uni.clearStorage();
        uni.switchTab({
          url: "/pages/mine/mineIndex",
        });
      }
    },
  });
};

const toOpen = () => {
  console.log(111111111);

  let redirect_uri = encodeURIComponent(
    "https://h5.qunxinghuzhu.com/h5/#/pages/mine/system/"
  );
  let appId = "wx5fcd79543f91406a";

  window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_wechat_redirect
     `;
};

function onBridgeReady() {}

const pay = () => {
  WeixinJSBridge.invoke(
    "getBrandWCPayRequest",
    {
      appId: "wx5fcd79543f91406a", //公众号ID，由商户传入
      timeStamp: new Date().getTime / 1000 + "", //时间戳，自1970年以来的秒数
      nonceStr: "4325435432543254325432545432545325", //随机串
      package: "prepay_id=wx2309422499772669b3f4f0dc67fd370001",
      signType: "RSA", //微信签名方式：
      paySign:
        "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==", //微信签名
    },
    function (res) {
      uni.showModal({
        title: "提示",
        content: JSON.stringify(res),
      });

      if (res.err_msg == "get_brand_wcpay_request:ok") {
        // 使用以上方式判断前端返回,微信团队郑重提示：
        //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠，商户需进一步调用后端查单确认支付结果。
      }
    }
  );
};

onLoad((option) => {
  let str = "";

  // 创建 URLSearchParams 实例
  const params = new URLSearchParams(window.location.search);

  // 获取单个参数的值
  const code = params.get("code"); // "alice"
  // const age = params.get('age');   // "25"

  // uni.showModal({
  //   title: "提示",
  //   content: "22222-----code====" + code,
  //   success: function (res) {},
  // });
});
</script>
<style lang="scss" scoped>
.system-button {
  margin: 34rpx;

  button {
    height: 54px;
    border-radius: 8px;
    background: #ffffff;
    box-sizing: border-box;
    border: 1px solid #0753fd;
    color: #111;
    margin-bottom: 34rpx;
    font-family: PingFang SC Medium;
    font-size: 16px;
    font-weight: normal;
    color: #111111;
    display: flex;
    align-items: center;
    justify-content: center;

    &::after {
      display: none;
    }
  }
}
</style>
